﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Environment.Commanding;
using System.Collections.ObjectModel;
using Kokomo.Environment.Hosting;

namespace Kokomo.Environment
{
	/// <summary>
	/// Represents a document that describes an error condition.
	/// </summary>
	/// <remarks>
	/// When an exception is throw and not handled, the environment
	/// displays the exception details to the user using this type.
	/// An instance created in response to a known condition should provide
	/// specific information, and provide commands via <see cref="CommandViewModels"/> to assist
	/// the user in diagnosing or correcting the error.
	/// For example, when an editor encounters an <see cref="System.IO.IOException"/>
	/// opening a file, it should provide a command to retry the operation.
	/// </remarks>
	[ViewType(typeof(ErrorDocumentView))]
	public class ErrorDocumentViewModel : DocumentViewModel
	{
		/// <summary>
		/// Initializes a new instance of <see cref="ErrorDocumentViewModel"/>.
		/// </summary>
		public ErrorDocumentViewModel()
		{
			this.Title = UiString.FromString(Messages.ErrorDocumentTitle);
			this._commandViewModels = new ObservableCollection<CommandViewModel>();
		}

		private UiString _mainCaption;
		/// <summary>
		/// Gets or sets the main caption.
		/// </summary>
		/// <remarks>
		/// The main caption is displayed in a larger font.
		/// It should be concise.
		/// </remarks>
		public UiString MainCaption
		{
			get { return this._mainCaption; }
			set
			{
				this._mainCaption = value;
				this.OnPropertyChanged("MainCaption");
			}
		}

		private UiString _detail;
		/// <summary>
		/// Gets or sets the error details.
		/// </summary>
		/// <remarks>
		/// The details are displayed in a normal font and may be
		/// lengthy, as to provide as much information as necessary
		/// to diagnose and correct the error.
		/// </remarks>
		public UiString Detail
		{
			get { return this._detail; }
			set
			{
				this._detail = value;
				this.OnPropertyChanged("Detail");
			}
		}

		private Exception _exception;
		/// <summary>
		/// Gets or sets the exception representing the error.
		/// </summary>
		/// <remarks>
		/// This property may be <c>null</c>.
		/// Any instance created in response to an exception should
		/// set this property.
		/// However, an application or editor may choose to create an
		/// <see cref="ErrorDocumentViewModel"/> for an error not caused
		/// by an exception.
		/// </remarks>
		public Exception Exception
		{
			get { return this._exception; }
			set
			{
				this._exception = value;
				this.OnPropertyChanged("Exception");
			}
		}

		private ObservableCollection<CommandViewModel> _commandViewModels;
		/// <summary>
		/// Gets the commands to display to the user.
		/// </summary>
		/// <remarks>
		/// The commands should be relevant to diagnosing or correcting the error.
		/// </remarks>
		public ObservableCollection<CommandViewModel> CommandViewModels
		{
			get { return this._commandViewModels; }
		}
	}
}
